<template>
  <div id='zhu'>
    <div class='zhuinfo'>
      <h2>树状图</h2>
      <div ref='main'
        class='main'></div>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'zhu',
  data() {
    return {
      echart: '',
    }
  },
  mounted() {
    this.echart = echarts.init(this.$refs.main)
    this.setOptions()
  },
  methods: {
    setOptions() {
      let option = {
        tooltip: {},
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        },
        yAxis: {
          type: 'value',
        },
        series: [
          {
            data: [120, 200, 150, 80, 70, 110, 130],
            type: 'bar',
            barWidth: '21%',
            itemStyle: {
              borderRadius: [50, 50, 0, 0],
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: '#83bff6' },
                { offset: 0.5, color: '#188df0' },
                { offset: 1, color: '#188df0' },
              ]),
            },
          },
        ],
      }
      option && this.echart.setOption(option)
    },
  },
}
</script>

<style lang='less'>
#zhu {
  width: 100%;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  .zhuinfo {
    width: 100%;
    height: 100%;
    background-color: #fff;
    border-radius: 4px;
    position: relative;
    .main {
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      right: 0;
      margin: auto;
      width: 50%;
      height: 50%;
    }
    h2 {
      position: absolute;
      left: 50%;
      top: 100px;
      margin-left: -36px;
    }
  }
}
</style>